﻿
<script type="text/javascript">
    //$(document).ready(function () {

        $("#sigin-lnk").click(function () {
            $('div#logon-box').modal({
                opacity: 0,
                overlayClose: true,
                position: ["25%", "67%"],
                onOpen: function (dialog) {
                    dialog.overlay.fadeIn('slow', function () {
                        dialog.data.hide();
                        dialog.container.fadeIn('slow', function () {
                            dialog.data.slideDown('slow');
                        });
                    });
                }
            });
        });

        var googleProviderBox = 'https://www.google.com/accounts/o8/id';
        var yahooProviderBox = 'https://me.yahoo.com';

        $("#google-provider-box").click(function () {
            $.ajax({
                url: '@Url.Action("Authenticate", "Account")',
                type: 'POST',
                data: ko.toJSON({ returnUrl: window.location.href, provider: googleProviderBox }),
                dataType: 'json',
                contentType: 'APPLICATION/JSON',
                success: function (result) {
                    if (result.Success) {
                        window.location.href = result.RedirectUrl;
                    }
                    if (!result.Success) {
                        $('#openid-message-box').text(result.Message);
                    }
                }
            });
        });

        $("#yahoo-provider-box").click(function () {
            $.ajax({
                url: '@Url.Action("Authenticate", "Account")',
                type: 'POST',
                data: ko.toJSON({ returnUrl: window.location.href, provider: yahooProviderBox }),
                dataType: 'json',
                contentType: 'APPLICATION/JSON',
                success: function (result) {
                    if (result.Success) {
                        window.location.href = result.RedirectUrl;
                    }
                    if (!result.Success) {
                        $('#openid-message-box').text(result.Message);
                    }
                }
            });
        });

        $("#signinBtn-box").click(function () {

            var email = $("#email-loginbox").val();
            var pwd = $("#pwd-loginbox").val();
            if (email == "") {
                $('#openid-message-box').text('Please enter email.');
            } else if (pwd == "") {
                $('#openid-message-box').text('Please enter password.');
            }
            if (email != "" && pwd != "") {
                var remember = ($('#remember-box').attr("checked") == null) ? "false" : "true";

                $.ajax({
                    url: '@Url.Action("LogOnAjax", "Account")',
                    type: 'POST',
                    data: ko.toJSON({ Email: email, Password: pwd, RememberMe: remember, returnUrl: '@Request.QueryString["returnUrl"]' }),
                    dataType: 'json',
                    contentType: 'APPLICATION/JSON',
                    success: function (result) {
                        window.location.href = result.returnUrl;


                        //alert(xhr.responseText);
                    }
                });
            }
        });
    //});

</script>
